package com.ajk.server.dao;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.ajk.server.dao.provider.TestAnswerProvider;
import com.ajk.server.model.TestAnswer;
import com.ajk.server.model.query.TestAnswerQuery;
import com.ajk.server.model.response.TestAnswerRes;
/**
 * 测试记录  <br>
 * t_test_answer <br>
 * v1.0 2016-05-01
 */
 public interface TestAnswerMapper {
 	
 	/**
 	*根据id删除 测试记录
 	*/
 	@Delete("delete from t_test_answer where id=#{id}")
 	public Integer deleteById(Integer id);
 	
 	/**
 	* 批量新增 测试记录
 	*/
 	@InsertProvider(method="batchInsert",type=TestAnswerProvider.class)
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="list[0].id")
 	public Integer batchInsert(List<? extends TestAnswer> testAnswers);
 	
 	/**
 	* 新增 测试记录
 	*/
 	@InsertProvider(method="insert",type=TestAnswerProvider.class)
	@Options(useGeneratedKeys=true)
 	public Integer insert(TestAnswer domain);
 
 	
 	/**
 	*更新 测试记录
 	*/
 	@UpdateProvider(method="update",type=TestAnswerProvider.class)
 	public Integer update(TestAnswer domain);
 	
 	/**
 	*根据ID查询 测试记录
 	*/
	@Select("select * from t_test_answer where id=#{id}")
	public TestAnswer findById(Integer id);
	
	@Select("select a.*,b.name paper_name from t_test_answer a,dict_test_category b where a.category_id=b.id and a.id=#{id}")
	public TestAnswerRes findResById(Integer id);
	
	
	/**
 	*通过query 查询 测试记录
 	*/
 	@SelectProvider(method="findByQuery",type=TestAnswerProvider.class)
 	public List<TestAnswerRes> findByQuery(TestAnswerQuery query);
 	
 	/**
 	*通过query count总条数
 	*/
 	@SelectProvider(method="countByQuery",type=TestAnswerProvider.class)
 	public Integer countByQuery(TestAnswerQuery query);
 	
 	/**
 	* 通过ids查询
 	*/
 	@SelectProvider(method="findByIds",type=TestAnswerProvider.class)
 	public List<TestAnswer> findByIds(List<Integer> ids);
 	
 	
 	@SelectProvider(method="findAnswerByUserIdParentId",type=TestAnswerProvider.class)
 	public List<TestAnswerRes> findAnswerByUserIdParentId(@Param("userId") Integer userId, @Param("start") Integer start, @Param("limit") Integer limit);
 	
 	@Select("select a.*,b.name paper_name from t_test_answer a,dict_test_category b where a.category_id=b.id and a.user_id=#{userId} order by id desc limit 1")
 	public TestAnswerRes findMyLastTestAnswerRes(Integer userId);

}	